var autoIncrement = require('mongoose-auto-increment')
var mongoose = require('mongoose');
var schema = mongoose.Schema;
var core = require('core');

var Merchant = function(){
    var personnel = new schema({
        openid : { type: String },
        level : { type: Number },
        recommend : { type: String }
    });
    var address = new schema({
        area : [],
        text : { type: String }
    });
    var merchantSchema = new schema({
        mid : { type: Number, index: true },
        name : { type: String, index: true },
        image : {type: String},
        address : address,
        time : { type: Date, default: Date.now },
        order: { type: Number },
        admin : { type: String },
        recommend : { type: String },
        personnel : [personnel],
        price : { type: Array, default: [] }
    });

    merchantSchema.plugin(core.db.plugin.increment, {
        model       : 'Merchant',
        field       : "mid",
        start       : 0,
        increasing  : 1
    });

    return mongoose.model('Merchant',merchantSchema, 'Merchant');
};

module.exports = Merchant;
